<?php

namespace app\v1\behavior;

class CORS
{
    public function run(){
        header("Content-type:text/json;charset=utf-8");
        header("Access-Control-Allow-Origin: *");
        header("Access-Control-Allow-Methods:POST,GET,DELETE,PATCH");
        //Header在设置时要对应前端axios设置了哪些值（前端使用vue的axios时）
        header("Access-Control-Allow-Headers: Content-Type,Content-Length,Accept-Encoding,X-Requested-with,Cache-Control,pragma,Authorization");
        header('Access-Control-Allow-Credentials: true');//支持cookie跨域

        if(request()->isOptions()){
            exit();
        }
    }
}